#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 998244353;
typedef long long LL;

int dis(int x,int y)
{
    if(x % 3 == 2 && y % 3 == 2)
    {
        return x + y + 2;
    }
    return x + y;
}

struct P{
    int x;
    int y;
    bool operator<(const P &o) const{
        if(dis(x,y) != dis(o.x,o.y)) return dis(x,y) < dis(o.x,o.y);
        else if(x != o.x) return x < o.x;
        else return y < o.y;
    }
};

void solve(){
    int n;
    cin >> n;
    int ll = 1;
    int rr = n;
    while(ll < rr)
    {
        int mid = ll + rr >> 1;
        if(4 * mid * mid >= 1 + 8 * n) rr = mid;
        else ll = mid + 1;
    }
    set<P> st1;
    set<P> st2;
    int mid = ll;
    for(int i = 1; i <= mid; i ++)
    {
        for(int j = 1;  j <= mid; j ++)
        {
            int ttx = (i - 1) * 3 + 1;
            int tty = (j - 1) * 3 + 1;      
            st1.insert({ttx,tty}), st1.insert({ttx + 1,tty}),st1.insert({ttx,tty + 1}),st1.insert({ttx + 1,tty + 1});
            st2.insert({ttx,tty});
        }
    }

    for(int i = 1;  i <= n; i ++)
    {
        int x;
        cin >> x;
        if(x == 0)
        {
            int x = (*st2.begin()).x;
            int y = (*st2.begin()).y;
            cout << x << ' ' << y << endl;
            st2.erase({x,y});
            if(st1.find({x,y}) != st1.end()) st1.erase({x,y}); 
        }
        else
        {
            int x = (*st1.begin()).x;
            int y = (*st1.begin()).y;
            cout << x << ' ' << y << endl;
            st1.erase({x,y});
            if(st2.find({x,y}) != st2.end()) st2.erase({x,y}); 
        }
    }
}

signed main(){
    int t = 1;
    cin >> t;
    while(t--)
    {
        solve();
    }
}


